package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    @Insert("insert into shopping_cart (name, image, user_id, dish_id, setmeal_id, dish_flavor, amount) values(#{name}, #{image}, #{userId}, #{dishId}, #{setmealId}, #{dishFlavor}, #{amount})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void add(ShoppingCart shoppingCart);

    @Select("select * from shopping_cart where user_id=#{userId}")
    List<ShoppingCart> list(Long userId);

    @Select("select count(*) from shopping_cart where dish_id=#{dishId} and user_id=#{userId}")
    long countByDishIdAndUserId(ShoppingCart shoppingCart);

    @Select("select * from shopping_cart where dish_id=#{dishId} and user_id=#{userId}")
    ShoppingCart getByDishIdAndUserId(ShoppingCart paras);

    @Update("update shopping_cart set number=#{number},amount=#{amount} where id=#{id}")
    void update(ShoppingCart shoppingCart);

    @Delete("delete from  shopping_cart where id=#{id}")
    void deleteById(Long id);

    @Delete("delete from  shopping_cart where user_id=#{userId}")
    void deleteByUserId(Long userId);

    @Select("select * from shopping_cart where user_id=#{userId}")
    List<ShoppingCart> getByUserId(Long userId);
}
